package org.arch_learn.dubbo_demo.service_consumer;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.arch_learn.dubbo_demo.service_consumer.service.DemoServiceConsumer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DubboTestMonitorMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(200);
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(DubboConsumerMain.ConsumerConfig.class);
        applicationContext.start();
        //获取消费者组件
        final DemoServiceConsumer consumer = applicationContext.getBean(DemoServiceConsumer.class);
        List<String> list = Arrays.asList("methodA", "methodB", "methodC");
        for (int i = 0; i < 2000; i++) {
            list.forEach(m -> executorService.execute(() -> {
                consumer.callMethod(m);
            }));
        }
        System.in.read();
    }

    @Configuration
    @EnableDubbo
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "org.arch_learn.dubbo_demo.service_consumer.service")
    static class ConsumerConfig {

    }
}
